package com.eastfair.common.controller;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.common.dto.CommonInterfaceCallRecordPageQuery;
import com.eastfair.common.dto.CommonInterfaceCallRecordSaveDTO;
import com.eastfair.common.dto.CommonInterfaceCallRecordUpdateDTO;
import com.eastfair.common.entity.CommonInterfaceCallRecord;
import com.eastfair.common.service.CommonInterfaceCallRecordService;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 
 * </p>
 *
 * @author clm
 * @date 2022-12-22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/commonInterfaceCallRecord")
@Api(value = "CommonInterfaceCallRecord", tags = "")
@PreAuth(replace = "common-service:commonInterfaceCallRecord:")
public class InterfaceCallRecordController extends SuperController<CommonInterfaceCallRecordService, Long, CommonInterfaceCallRecord, CommonInterfaceCallRecordPageQuery, CommonInterfaceCallRecordSaveDTO, CommonInterfaceCallRecordUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Resource
    private CommonInterfaceCallRecordService commonInterfaceCallRecordService;

    @Override
    public void handlerResult(IPage<CommonInterfaceCallRecord> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<CommonInterfaceCallRecord> commonInterfaceCallRecordList = list.stream().map((map) -> {
            CommonInterfaceCallRecord commonInterfaceCallRecord = CommonInterfaceCallRecord.builder().build();
            //TODO 请在这里完成转换
            return commonInterfaceCallRecord;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(commonInterfaceCallRecordList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<CommonInterfaceCallRecordPageQuery> params) {
        CommonInterfaceCallRecordPageQuery pageQuery = params.getModel();
        //分页处理
        if (ContextUtil.getProjectId() != null) {
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }

    }


    @PostMapping("/test")
    R<Boolean> test(@RequestBody CommonInterfaceCallRecordPageQuery param) {

//        commonInterfaceCallRecordService.doProcess(param);


        return R.success(true);
    }

}
